package logic

import (
	"context"
	"net/http"

	"zero_six/user/internal/svc"
	"zero_six/user/pb/user"

	"github.com/zeromicro/go-zero/core/logx"
)

type GetUserInfoLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewGetUserInfoLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetUserInfoLogic {
	return &GetUserInfoLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *GetUserInfoLogic) GetUserInfo(in *user.RegisterRequest) (*user.Response, error) {
	// todo: add your logic here and delete this line
	u, err := l.svcCtx.UserModel.FindOneByMobile(context.Background(), in.Mobile)
	if err != nil {
		return &user.Response{
			Code: http.StatusAccepted,
			Msg:  "用户信息查询失败",
		}, nil
	}
	return &user.Response{
		Code:     http.StatusOK,
		Msg:      "查询成功",
		Username: u.Username,
		UserId:   u.Id,
	}, nil
}
